package com.jinghong.registerlogin.mapper;

import com.jinghong.registerlogin.model.pojo.Paper;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:PapperMapper
 * Package:com.jinghong.registerlogin.mapper
 * Description:
 *
 * @Author: 寻月君子
 * &#064;CreatTime:2024/5/20  15:25
 * Version:1.0
 */

@Mapper
public interface PaperMapper {
    //增

    /**
     * 新增试卷
     * @param paper 试卷
     */
    @Insert("insert into `register_login`.paper( subject,level,difficulty,topic,user_id, single_num, multiple_num, judge_num, word_num, total_score, status, creat_time, update_time) values (#{subject},#{level},#{difficulty},#{topic},#{userId},#{singleNum,jdbcType=INTEGER},#{multipleNum,jdbcType=INTEGER},#{judgeNum,jdbcType=INTEGER},#{wordNum,jdbcType=INTEGER},#{totalScore},#{status},now(),now())")
    @SelectKey(before = false,keyProperty = "id",resultType = Integer.class,statement = "SELECT LAST_INSERT_ID()")
    void insert(Paper paper);


    /**
     * 批量删除试卷
     * @param ids 试卷的ids
     */
    void delete(List<Integer> ids);


    /**
     * 删除单个试卷
     * @param id id
     */
    @Delete("delete from `register_login`.paper where id = #{id}")
    void deleteById(Integer id);

    //改

    /**
     * 更改试卷信息
     * @param paper 试卷
     */
    void update(Paper paper);


    //查

    /**
     * 条件分页查询
     * @param topic
     * @param userId
     * @param status
     * @param began
     * @param end
     * @return 试卷集合
     */
    List<Paper> list(String subject,String topic, Integer userId, Integer status, LocalDateTime began, LocalDateTime end);


    /**
     * 编辑试卷时数据回显
     * @param id id
     * @return paper
     */
    @Select("select * from `register_login`.paper where id = #{id}")
    Paper getById(Integer id);

}
